package com.mvu.banana.user.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.*;
import com.mvu.banana.common.client.CommonComposite;
import com.mvu.banana.common.client.InputColumn;
import com.mvu.banana.common.client.InputSet;
import com.mvu.banana.common.client.UiOut;
import com.mvu.banana.domain.client.MyConstants;
import com.mvu.banana.user.generated.SearchProfileDTO;

import java.util.List;

/**
 * gantz - 6/4/11 - 12:43 PM
 * @generate-server-code
 */
public class SearchProfile extends CommonComposite<SearchProfileDTO> implements ClickHandler {
  /** @see Gender **/
  public ListBox gender;
  /** @see java.lang.Integer **/
  public ListBox minAge;
  /** @see java.lang.Integer **/
  public ListBox maxAge;
  /** @see java.lang.String **/
  public TextBox city;
  /** @see java.lang.String **/
  public TextBox name;
  /** @see java.lang.Boolean **/
  public CheckBox hasPicture;
  Button search;
  ProfileList results = new ProfileList();
  Label error = new Label(MyConstants.get.noResults());

  public SearchProfile() {
    super(new SearchProfileDTO());
    VerticalPanel main = new VerticalPanel();
    initWidget(main);
    AgeRangeInput ageRange = new AgeRangeInput(minAge, maxAge);
    search = new Button(MyConstants.get.search());
    search.addClickHandler(this);
    InputSet criteriaInput = new InputSet(
            new InputColumn(gender, ageRange, city),
            new InputColumn(name, hasPicture, search)
    );
    main.add(criteriaInput);
    results = new ProfileList();
    results.setVisible(false);
    main.add(results);
    error.setVisible(false);
    main.add(error);
  }

  @UiOut
  public void setResults(List<ProfileDTO> dtos){
    results.setRowCount(dtos.size());
    results.setRowData(0, dtos);
    results.setVisible(!dtos.isEmpty());
    error.setVisible(dtos.isEmpty());
  }

  @Override
  public void onClick(ClickEvent event) {
    post(search);
  }
}